//
//  WWTBtnView.m
//  ERP
//
//  Created by QA on 16/6/6.
//  Copyright © 2016年 ShangHai HaoLei Software Technology Co., Ltd. All rights reserved.
//

#import "WWTBtnView.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "UIColorDispose.h"

@implementation WWTBtnView
@synthesize titleLable;
@synthesize detailLable;
@synthesize imageView;
@synthesize imageMarkView;

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width-120, frame.size.height - 80, 120, 80)];
        //imageView.image = [UIImage imageNamed:@"icon_error_coupon.png"];
        imageView.contentMode = UIViewContentModeBottomRight | UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 9, frame.size.width, 22)];
        //titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.font = [UIFont systemFontOfSize:16];
        titleLable.textColor = [UIColorDispose colorWithHexString:@"555555"];
        [self addSubview:titleLable];
        
        self.detailLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, frame.size.width, 22)];
        //detailLable.textAlignment = NSTextAlignmentCenter;
        detailLable.font = [UIFont systemFontOfSize:12];
        detailLable.textColor = [UIColorDispose colorWithHexString:@"8C8C8C"];
        [self addSubview:detailLable];
        
    }
    return self;
}

//左图右文字
-(id)initWithLeftImgRightTextFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, frame.size.height/2 - 40/2, 40, 40)];
        //imageView.image = [UIImage imageNamed:@"icon_error_coupon.png"];
        imageView.contentMode = UIViewContentModeBottomRight | UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(70, frame.size.height/2 - 22/2, frame.size.width - 70, 22)];
        //titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.font = [UIFont systemFontOfSize:16];
        titleLable.textColor = [UIColorDispose colorWithHexString:@"#333333"];
        [self addSubview:titleLable];
        
        self.imageMarkView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 36, 36)];
        //imageView.image = [UIImage imageNamed:@"icon_error_coupon.png"];
        [self addSubview:imageMarkView];
    }
    return self;
}

//左图右文字
-(id)initWithLeftImgRightTextFrame:(CGRect)frame markNumber:(NSInteger)markCount
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, frame.size.height/2 - 40/2, 40, 40)];
        //imageView.image = [UIImage imageNamed:@"icon_error_coupon.png"];
        imageView.contentMode = UIViewContentModeBottomRight | UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(70, frame.size.height/2 - 22/2, frame.size.width - 70, 22)];
        //titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.font = [UIFont systemFontOfSize:16];
        titleLable.textColor = [UIColorDispose colorWithHexString:@"#333333"];
        [self addSubview:titleLable];
        
        self.imageMarkView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 36, 36)];
        //imageView.image = [UIImage imageNamed:@"icon_error_coupon.png"];
        [self addSubview:imageMarkView];
        
        if(markCount > 0){
            UIView *markView = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width - 20, 12, 8,8)];
            markView.backgroundColor = [UIColor redColor];
            [markView.layer setCornerRadius:4];//圆角
            [self addSubview:markView];
        }
    }
    return self;
}

-(id)initWithPingImageFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width-100, frame.size.height - 75, 100, 75)];
        //imageView.image = [UIImage imageNamed:@"icon_error_coupon.png"];
        imageView.contentMode = UIViewContentModeBottomRight | UIViewContentModeScaleAspectFit;
//        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 9, frame.size.width, 22)];
        //titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.font = [UIFont systemFontOfSize:16];
        titleLable.textColor = [UIColorDispose colorWithHexString:@"555555"];
        [self addSubview:titleLable];
        
        self.detailLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, frame.size.width, 22)];
        //detailLable.textAlignment = NSTextAlignmentCenter;
        detailLable.font = [UIFont systemFontOfSize:12];
        detailLable.textColor = [UIColorDispose colorWithHexString:@"8C8C8C"];
        [self addSubview:detailLable];
        
    }
    return self;
}

-(id)initWithMiniFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width-60 - 5, frame.size.height - 60 - 5, 60, 60)];
        //imageView.image = [UIImage imageNamed:@"icon_error_coupon.png"];
        //imageView.contentMode = UIViewContentModeBottomRight | UIViewContentModeScaleAspectFit;
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 9, frame.size.width, 22)];
        //titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.font = [UIFont systemFontOfSize:15];
        titleLable.textColor = [UIColorDispose colorWithHexString:@"555555"];
        [self addSubview:titleLable];
        
        self.detailLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 28, frame.size.width, 22)];
        //detailLable.textAlignment = NSTextAlignmentCenter;
        detailLable.font = [UIFont systemFontOfSize:11];
        detailLable.textColor = [UIColorDispose colorWithHexString:@"8C8C8C"];
        [self addSubview:detailLable];
        
    }
    return self;
}

-(id)initWithVerticalFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width/2 - 30, frame.size.height - 60 - 5, 60, 60)];
        //imageView.image = [UIImage imageNamed:@"icon_error_coupon.png"];
        //imageView.contentMode = UIViewContentModeBottomRight | UIViewContentModeScaleAspectFit;
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, frame.size.width, 22)];
        titleLable.textAlignment = NSTextAlignmentCenter;
        titleLable.font = [UIFont systemFontOfSize:14];
        titleLable.textColor = [UIColorDispose colorWithHexString:@"555555"];
        [self addSubview:titleLable];
        
        self.detailLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 27, frame.size.width, 22)];
        detailLable.textAlignment = NSTextAlignmentCenter;
        detailLable.font = [UIFont systemFontOfSize:10];
        detailLable.textColor = [UIColorDispose colorWithHexString:@"8C8C8C"];
        [self addSubview:detailLable];
        
    }
    return self;
}

-(void)setTitle:(NSString *)title detail:(NSString *)detail imageStr:(NSString *)imageStr
{
    titleLable.text = title;
    detailLable.text = detail;
    [imageView sd_setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage new]];
}

-(void)setTitle:(NSString *)title detail:(NSString *)detail imageStr:(NSString *)imageStr imageMark:(NSString *)markImage
{
    titleLable.text = title;
    detailLable.text = detail;
    [imageView sd_setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage new]];
    imageMarkView.image = [UIImage imageNamed:markImage];
}

@end
